﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace TFSCodeReviewHelper
{
    public enum DifferenceParticiaption
    {
        None,
        First,
        Last
    }

    public delegate void ChangeSelectedEventHandler(object sender, ChangeSelectedArgs e);

    /// <summary>
    /// Interaction logic for ChangesetControl.xaml
    /// </summary>
    public partial class ChangesetControl : UserControl, INotifyPropertyChanged 
    {
        public event ChangeSelectedEventHandler Selected;

        private AssetChange _Change;
        public AssetChange Change
        {
            get { return _Change; }
            set
            {
                _Change = value;
                BuildControl();
            }
        }
        public ChangesetControl()
        {
            InitializeComponent();
        }

        public ChangesetControl(AssetChange change) : this()
        {
            Change = change;
        }

        protected void BuildControl()
        {
            DataContext = _Change;

            if (Change == null)
            {
                _ChangeButton.Visibility = System.Windows.Visibility.Hidden;   
                _SinceLast.Visibility = System.Windows.Visibility.Hidden;
            }
            else
            {
                _ChangeButton.Content = Change.Number;
                if (Change.ChangesSincePerviousChange == 0)
                    _SinceLast.Visibility = System.Windows.Visibility.Hidden;
                else
                    _SinceLast.Text = Change.ChangesSincePerviousChange.ToString();
            }
        }

        private void _ChangeButton_Click(object sender, RoutedEventArgs e)
        {
            if (Selected != null)
                Selected(this, new ChangeSelectedArgs(Change));
        }


        public void MakeFirstEntry()
        {
            _SinceLast.Visibility = System.Windows.Visibility.Collapsed;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged(string propertyName)
        {
            if (null != PropertyChanged)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public class ChangeSelectedArgs : EventArgs
    {
        public AssetChange AssetChange;

        public ChangeSelectedArgs(AssetChange assetChange)
        {
            AssetChange = assetChange;
        }
    }
}
